package com.ljb.utilslibrary.commUtils;

import android.os.Handler;
import android.os.Looper;

/**
 * 主线程和子线程快速切换的工具类
 * Created by lijianbin on 2016/10/12.
 */
public class ThreadUtils {

    //初始化主线程handler
    private static Handler mHandler = new Handler(Looper.getMainLooper());

    private ThreadUtils() {
    }

    /**
     * 切换到主线程
     *
     * @param runnable
     */
    public static void runUIThread(Runnable runnable) {
        //利用handler向主线程消息队列发送消息
        mHandler.post(runnable);
    }

    /**
     * 切换到子线程
     *
     * @param runnable
     */
    public static void runInThread(Runnable runnable) {
        //开启子线程,执行runable中的run方法
        new Thread(runnable).start();
    }
}
